#include "Renderer.hpp"
 
Renderer::Renderer(sf::RenderWindow &renderWindow) :
m_renderWindow(renderWindow)
{
}	
void Renderer::drawBackground(Map& map)
{
	// draw background
	sf::Sprite back(map.background());
	m_renderWindow.Draw(back);
}

void Renderer::drawBoxes(Map& map)
{
	// draw boxes
	std::map<unsigned int, BoxPtr>& boxes = map.boxes();
	std::map<unsigned int, BoxPtr>::iterator itor;
	for(itor = boxes.begin(); itor != boxes.end(); ++itor)
		m_renderWindow.Draw(*(itor->second.get()));
}

void Renderer::drawTank(TankPtr tank)
{
	ImagePtr groundImage = tank->groundImage();
	ImagePtr cannonImage = tank->cannonImage();
	 
	if(groundImage.get() != NULL)
	{
		groundImage->CreateMaskFromColor(sf::Color(97,68,43));
		sf::Sprite ground(*groundImage);	
		ground.SetCenter(80,80);
		ground.SetPosition(tank->position());
		m_renderWindow.Draw(ground);
	}
	if(cannonImage.get() != NULL)
	{
		cannonImage->CreateMaskFromColor(sf::Color(97,68,43));
		sf::Sprite cannon(*cannonImage);
		cannon.SetCenter(80,80);
		cannon.SetPosition(tank->position());
		m_renderWindow.Draw(cannon);
	}
}

void Renderer::drawTanks(const std::list<TankPtr> tanks)
{
	std::list<TankPtr>::const_iterator citor = tanks.begin();
	for(; citor != tanks.end(); ++citor)
		drawTank(*citor);
}

void Renderer::drawBullet()
{
}

void Renderer::drawExplosion()
{
}	
